package com.tushare.util;

import com.tushare.entity.Daily;

import java.util.List;

public class CalBollUtil {
    private static final int T = 20;
    private static final int K = 2;

    public static void calBoll(List<Daily> dailyList) {
        for (int i = T - 1; i < dailyList.size(); i++) {
            float sum = 0;
            for (int j = T - 1; j >= 0; j--) {
                sum += dailyList.get(i - j).getClose();
            }
            double z = sum / T;
            double sumMD = 0;
            for (int j = T - 1; j >= 0; j--) {
                double thisClose = dailyList.get(i - j).getClose();
                double cma = thisClose - z; // C-MB
                sumMD += cma * cma;
            }
            double md = Math.pow(sumMD / (T - 1), 1.0 / K); // MD=前n日C-MB的平方和来开根
            double s = z + md * K;
            double x = z - md * K;
            System.out.println(s);
            System.out.println(z);
            System.out.println(x);
        }
    }

}
